package com.ams.misc;

import java.nio.ByteBuffer;

import com.ams.io.BufferAllocator;

public class MemBenchmark {

    public static void main(String[] args) {
        int n = 10000;
        int size = 10 * 1024;
        long t1 = System.currentTimeMillis();
        for (int i = 0; i < n; i++) {
            byte[] a = new byte[size];
        }
        long t2 = System.currentTimeMillis();
        System.out.println("heap time = " + (t2 - t1));

        BufferAllocator allocator = new BufferAllocator();
        allocator.setPoolSize(n * size + 100 * size);
        allocator.init();
        long tt1 = System.currentTimeMillis();
        for (int i = 0; i < n; i++) {
            ByteBuffer a = allocator.allocate(size);
        }
        long tt2 = System.currentTimeMillis();
        System.out.println("slab time = " + (tt2 - tt1));

        long ttt1 = System.currentTimeMillis();
        for (int i = 0; i < n; i++) {
            ByteBuffer a = ByteBuffer.allocateDirect(size);
        }
        long ttt2 = System.currentTimeMillis();
        System.out.println("direct buffer time = " + (ttt2 - ttt1));

    }
}
